package com.zyh.stream;

import com.zyh.domain.Student;
import org.junit.jupiter.api.Test;

import java.util.*;

/**
 * @Author zyh
 * @Date 2024/8/16 10:40
 * @Description 判断/匹配
 */

public class StreamDemo2 {
    @Test
    public void test2(){
        Map<Integer, Student> map=new HashMap<>();
        map.put(1,new Student("zyh","男",18,180.6));
        map.put(2,new Student("zyh1","男",21,176.0));
        map.put(3,new Student("zyh2","女",23,173.0));
        map.forEach((key,value)-> System.out.println(key+"--"+value));
    }
    @Test
    public void test1(){
        List<Integer> list = Arrays.asList(2, 3, 4, 5, 1, 6, 8, 5, 8, 9);
        //找到任意一个大于5的数
        Integer integer = list.stream().filter(item -> item > 5).findAny().get();
        System.out.println("integer = " + integer);
        //找到第一个奇数
        Integer integer1 = list.stream().filter(item -> item % 2 == 1).findFirst().get();
        System.out.println("integer1 = " + integer1);
        //匹配是否有大于5的数
        boolean b = list.stream().anyMatch(item -> item > 5);
        System.out.println("b = " + b);
        //匹配是否有100
        boolean b1 = list.stream().noneMatch(i -> i == 100);
        System.out.println("b1 = " + b1);
        boolean b2 = list.stream().anyMatch(i -> i == 100);
        System.out.println("b2 = " + b2);
    }
}
